<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>三个数排序</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 400px;
            margin: 0 auto;
            padding: 20px;
        }
        .container {
            display: flex;
            flex-direction: column;
            gap: 10px;
        }
        input {
            padding: 8px;
            font-size: 16px;
        }
        button {
            padding: 10px;
            background-color: #4CAF50;
            color: white;
            border: none;
            cursor: pointer;
            font-size: 16px;
        }
        button:hover {
            background-color: #45a049;
        }
        .result {
            margin-top: 20px;
            font-size: 18px;
            font-weight: bold;
        }
        .error {
            color: red;
            margin-top: 5px;
        }
    </style>
</head>
<body>
    <h2>三个数排序</h2>
    <div class="container">
        <input type="number" id="num1" placeholder="输入第一个数">
        <div id="error1" class="error"></div>
        <input type="number" id="num2" placeholder="输入第二个数">
        <div id="error2" class="error"></div>
        <input type="number" id="num3" placeholder="输入第三个数">
        <div id="error3" class="error"></div>
        <button onclick="sortNumbers()">排序</button>
        <div id="result" class="result"></div>
    </div>

    <script>
        function sortNumbers() {
            // 清除之前的错误信息
            document.getElementById('error1').textContent = '';
            document.getElementById('error2').textContent = '';
            document.getElementById('error3').textContent = '';
            document.getElementById('result').textContent = '';
            
            // 获取输入的值
            const num1 = document.getElementById('num1').value;
            const num2 = document.getElementById('num2').value;
            const num3 = document.getElementById('num3').value;
            
            // 验证输入是否为空
            let isValid = true;
            if (num1 === '') {
                document.getElementById('error1').textContent = '请输入第一个数';
                isValid = false;
            }
            if (num2 === '') {
                document.getElementById('error2').textContent = '请输入第二个数';
                isValid = false;
            }
            if (num3 === '') {
                document.getElementById('error3').textContent = '请输入第三个数';
                isValid = false;
            }
            
            if (!isValid) return;
            
            // 转换为数字
            const n1 = parseFloat(num1);
            const n2 = parseFloat(num2);
            const n3 = parseFloat(num3);
            
            // 排序逻辑
            let sorted = [];
            if (n1 >= n2 && n1 >= n3) {
                sorted.push(n1);
                if (n2 >= n3) {
                    sorted.push(n2, n3);
                } else {
                    sorted.push(n3, n2);
                }
            } else if (n2 >= n1 && n2 >= n3) {
                sorted.push(n2);
                if (n1 >= n3) {
                    sorted.push(n1, n3);
                } else {
                    sorted.push(n3, n1);
                }
            } else {
                sorted.push(n3);
                if (n1 >= n2) {
                    sorted.push(n1, n2);
                } else {
                    sorted.push(n2, n1);
                }
            }
            
            // 显示结果
            document.getElementById('result').innerHTML = 
                `排序结果: ${sorted[0]}, ${sorted[1]}, ${sorted[2]}`;
        }
    </script>
</body>
</html>